package com.nondo.rdp.finance.endpoint;

import com.nondo.rdp.auth.common.UserUtils;
import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.auth.event.LoginApplicationEvent;
import com.nondo.rdp.core.model.View;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 测试接口类，用于调试和功能模拟
 */
@RestController
@RequestMapping("/api/test")
public class TestEndpoint {

    @Autowired
    private ApplicationEventPublisher applicationEventPublisher;

    @RequestMapping("")
    public View<String> index(HttpServletRequest request, HttpServletResponse response) {
        View view = new View(200, "获取数据成功");

        view.setData("hello world");

        User user = UserUtils.getUser(request, response);

        applicationEventPublisher.publishEvent(new LoginApplicationEvent(this, user));
//        applicationEventPublisher.publishEvent(new PointApplicationEvent(this, user, PointApplicationListener.TYPE_REGISTER));

        return view;
    }
}
